home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: stuart.hayes@baesema.co.uk
- Newsgroups: comp.lang.c
- Subject: Re: qsort help
- Date: Wed, 03 Jan 1996 11:18:33 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4cdomq$jgt@dub-news-svc-5.compuserve.com>
- References: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu>
- NNTP-Posting-Host: ad05-010.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu) wrote:
-
- >Hi, I am having some problems with the qsort routine.
-
-
- >int (*compar)(int *a, int *b)
- Function declaration should be:
- int compar(int *a, int *b)
- Should also declare function in header file or top of source for
- completeness
- >{
- > if (*a < *b) return -1;
- > else if (*a == *b) return 0;
- > else return 1;
- >}
-
-
- Alternatively to declaring function in header file could just declare
- in the function below:
- >int return_moved_contour(int ix, int iy)
- >{
- int (*compar)(int *a, int *b);
- > int i, ac, count=0;
- > int y_coord[10]; /* stores y coordinates whose x == ix */
-
- > for (ac=0; ac<areaindex; ac++)
- > {
- > for (i=0; i<index[ac]; i++)
- > {
- > if (xpos[ac][i] == ix) y_coord[count++] = ypos[ac][i];
- > }
- > if (count == 0) continue; /* not in this contour */
- > else {
- > qsort(y_coord, count, sizeof(int), compar);
- > i = 0;
- > while (i<count/2) {
- > if ((y_coord[i] <= iy) && (y_coord[i+1] >= iy))
- > return ac;
- > else i+=2;
- > }
- > }
- > }
- > return -1; /* cursor not within a contour, no response will be generated */
- >}
-
- >When I tried to compile, an error was generated:
- > Error: try.c, line 791: compar must have function type
-
- >I doublechecked the man page of qsort but still can't figure out what's
- >wrong.
-
- >Could someone give me a hand here?
-
- >Thanks.
-
- >Xiaoyi
-
- This is a first preliminary stab at this, haven't tried it.
- Hope of some help.
-
-
- Stuart
-
-